//
//  M_MineViewController.m
//  Model
//
//  Created by apple on 2018/7/9.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "M_MineViewController.h"
#import "M_MineOneTableViewCell.h"
#import "M_MineTwoTableViewCell.h"
#import "M_MineCoreViewController.h"
#import "M_MineChongZhiViewController.h"//充值
#import "M_MineSettingViewController.h"//设置
#import "M_MineCollectionaViewController.h"//收藏
#import "M_MineJiFenViewController.h"//我的积分
#import "M_MineHuoBiViewController.h"//货币
#import "M_MineHuiYuanViewController.h"//会员
@interface M_MineViewController ()<UITableViewDelegate, UITableViewDataSource>
{
    UIView *vipView;//vip弹窗
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableDictionary *dataDic;

@end

@implementation M_MineViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self data];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
   
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creationView];
    [self regeditCell];

    
    
    // Do any additional setup after loading the view.
}
- (void)creationView{
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, (KIsiPhoneX?-44:-20), DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT + (KIsiPhoneX?44:20)-49);
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = getColor(@"f7f7f7");
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
}
- (NSMutableDictionary *)dataDic{
    
    if (!_dataDic) {
        _dataDic = [NSMutableDictionary dictionary];
    }
    return _dataDic;
    
}
- (void)data{
    
//    self.dataDic = [NSMutableDictionary dictionary];
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    
    [[MNetworkHandler sharedInstance]conURL:UserInfo networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"Status"]intValue]==200) {
            
            self.dataDic = returnData[@"Data"];
            NSLog(@"%@", self.dataDic);
            [self.tableView reloadData];
            
        }
        
        else {
            
//            [PublicFunction showAlert:nil message:[returnData objectForKey:@"Msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
    
}
- (void)regeditCell{
    
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"M_MineOneTableViewCell" bundle:nil] forCellReuseIdentifier:@"M_MineOneTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"M_MineTwoTableViewCell" bundle:nil] forCellReuseIdentifier:@"M_MineTwoTableViewCell"];
    
    
}
#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 0;
}

#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else{
        
        return 1;
        
    }
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 260;
    }else{
        
        return DEF_SCREEN_WIDTH*1.5;
        
    }
    
    
}
#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
        
        M_MineOneTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"M_MineOneTableViewCell" forIndexPath:indexPath];
        
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.headBtn addTarget:self action:@selector(coreClick) forControlEvents:UIControlEventTouchUpInside];
//        NSMutableDictionary *dic = self.dataArr[0];
        cell.name.text = [NSString stringWithFormat:@"昵称: %@",[self.dataDic objectForKey:@"username"]];
        cell.userId.text = [NSString stringWithFormat:@"ID: %@",[self.dataDic objectForKey:@"userId"]];
        [cell.headImgView sd_setImageWithURL:[NSURL URLWithString:[self.dataDic objectForKey:@"headpicture"]] placeholderImage:[UIImage imageNamed:@"headmoren"]];
        cell.money.text = [NSString stringWithFormat:@"%d",[[self.dataDic objectForKey:@"money"] intValue]];
        cell.dengJi.text =[NSString stringWithFormat:@"%d",[[self.dataDic objectForKey:@"rank"] intValue]];
        cell.guanZhu.text = [NSString stringWithFormat:@"%d",[[self.dataDic objectForKey:@"FollowCount"] intValue]];

        [cell.huoBiButton addTarget:self action:@selector(huoBiClick) forControlEvents:UIControlEventTouchUpInside];
        
        return cell;
        
    }else{
        M_MineTwoTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"M_MineTwoTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.chongZhBtn addTarget:self action:@selector(chongZhiClick) forControlEvents:UIControlEventTouchUpInside];
        [cell.settingBtn addTarget:self action:@selector(settingClick) forControlEvents:UIControlEventTouchUpInside];
        [cell.collectionBtn addTarget:self action:@selector(collectionClick) forControlEvents:UIControlEventTouchUpInside];
        [cell.vipButton addTarget:self action:@selector(vipClick) forControlEvents:UIControlEventTouchUpInside];
        [cell.jifenButton addTarget:self action:@selector(jifenClick) forControlEvents:UIControlEventTouchUpInside];
        return cell;
        
    }
    
    
    
}

#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
///货币
- (void)huoBiClick{
    M_MineHuoBiViewController *vc = [[M_MineHuoBiViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
////个人中心
- (void)coreClick{
    M_MineCoreViewController *vc = [[M_MineCoreViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}
//设置
- (void)settingClick{
    M_MineSettingViewController *vc = [[M_MineSettingViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
//充值服务
- (void)chongZhiClick{


    M_MineChongZhiViewController *vc = [[M_MineChongZhiViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}
//我的收藏
- (void)collectionClick{
    
    M_MineCollectionaViewController *vc = [[M_MineCollectionaViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
//vip
- (void)vipClick{

    M_MineHuiYuanViewController *vc = [[M_MineHuiYuanViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

////////////////积分
- (void)jifenClick{
    M_MineJiFenViewController *vc = [[M_MineJiFenViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
